/*
   Copyright (c) 2023 李伟国
   learner-platform is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
               http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details. 
*/

package cn.platform.service.impl;

import cn.platform.entity.Problem;
import cn.platform.entity.ProblemSet;
import cn.platform.mapper.ProblemMapper;
import cn.platform.mapper.ProblemSetMapper;
import cn.platform.service.IProblemSetService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProblemSetServiceImpl extends ServiceImpl<ProblemSetMapper, ProblemSet> implements IProblemSetService {
    @Autowired
    private ProblemMapper problemMapper;
    /**
     * 获得对应题目集中的题目列表
     *
     * @param setId 题目集id
     * @return 题目列表
     */
    @Override
    public List<Problem> getProblemListBySetId(Long setId) {
        List<Problem> problemListBySetList = problemMapper.getProblemListBySetId(setId);
        return problemListBySetList;
    }

    /**
     * 从题目集中删除题目
     *
     * @param problemSet 题目集与题目
     * @return 结果
     */
    @Override
    public boolean deleteProblemBySetId(ProblemSet problemSet) {
        int i = this.baseMapper.deleteById(problemSet.getId());
        return i>0;
    }

    /**
     * 从题目集中增加题目
     *
     * @param problemSet 题目集与题目
     * @return 结果
     */
    @Override
    public boolean addProblemBySetId(ProblemSet problemSet) {
        int insert = this.baseMapper.insert(problemSet);
        return insert>0;
    }
}
